package aopalliance.intercept.MethodInterceptor;

import java.util.Arrays;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;

public class LoggingAroundAdvice implements MethodInterceptor {
	private Logger log = Logger.getLogger(getClass());
	
	public Object invoke(MethodInvocation invocation) throws Throwable {
		log.info("The method " + invocation.getMethod().getName() + "() begins with " + Arrays.toString(invocation.getArguments()));
		
		try {
			Object result = invocation.proceed();
			log.info("The method " + invocation.getMethod().getName() + "() ends with " + result);
			
			return result;
		} catch (IllegalArgumentException e) {
			log.error("Illegal argument " + Arrays.toString(invocation.getArguments()) + " for method " + invocation.getMethod().getName() + "()");
			
			throw e;
		}
	}

}
